package com.sumainfor.pc.market.service;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.utlis.ListMapRepeat;
import com.sumainfor.pc.market.dao.CommunityMapper;
import com.sumainfor.pc.market.dao.StreetMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 * 街道
 * @Auther: zhlu
 * @Date: 2019/3/11 17:56
 * @Description:
 */
@Service
public class StreetService {
    Logger log= LoggerFactory.getLogger(CityService.class);

    @Autowired
    StreetMapper StreetMapper;

    @Autowired
    CommunityMapper CommunityMapper;

    /**
     * 功能描述: 
     * 根据区编号获取街道列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/11 17:59
     */
    public List<Map<String,Object>>getStreetList(Map<String,Object>params){
        //数据拦截类型   all不拦截    term项目已有省市区
        if(FieldCheckUtil.isMapFieldNotNull(params,new String[]{"stemDataType"})){
            if(params.get("stemDataType").equals("term")||params.get("stemDataType").toString()=="term"){
                //获取现有项目的省市区
                List<Map<String,Object>>getCommunityTermList= CommunityMapper.getCommunityTermList(params);
                log.info("getCommunityTermList----"+getCommunityTermList);
                //接收去重之后的数据
                List<Map<String,Object>>ComList= ListMapRepeat.removeRepeatMapByKey(getCommunityTermList,"StreetID");

                //重新组成String集合in查询
                List<String>StreetNameList=new ArrayList<>();
                for(Map<String,Object> map:ComList){
                    StreetNameList.add(map.get("StreetID").toString());
                }
                params.put("StreetList",StreetNameList);
            }
        }
        List<Map<String,Object>> getStreetList=StreetMapper.getStreetList(params);
        return getStreetList;
    }

}
